package com.jhx.common.widget

import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.View

/**
 * RecyclerView分隔线
 *
 * @author jack 2017-05-03 13:04
 */
class ItemDecoration(private val mLineHeight: Int, private val mOrientation: Int) : RecyclerView.ItemDecoration() {

    private val mDivider: Drawable? = null

    init {
        if (mOrientation != HORIZONTAL_LIST && mOrientation != VERTICAL_LIST) {
            throw IllegalArgumentException("invalid orientation")
        }
    }

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {
        super.getItemOffsets(outRect, view, parent, state)
        if (mOrientation == HORIZONTAL_LIST) {
            outRect.set(0, 0, 0, mLineHeight)
        } else {
            outRect.set(0, 0, mLineHeight, 0)
        }

    }

    companion object {
        val HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL
        val VERTICAL_LIST = LinearLayoutManager.VERTICAL
    }
}
